/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.upn.sigemfi.seg.bc;

import edu.upn.sigemfi.seg.be.PersonaNatural;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Administrador
 */
@Stateless
public class PersonaNaturalFacade implements PersonaNaturalFacadeLocal {

    @PersistenceContext
    private EntityManager em;

    public void create(PersonaNatural personaNatural) {
        em.persist(personaNatural);
    }

    public void edit(PersonaNatural personaNatural) {
        em.merge(personaNatural);
    }

    public void remove(PersonaNatural personaNatural) {
        em.remove(em.merge(personaNatural));
    }

    public PersonaNatural find(Object id) {
        return em.find(PersonaNatural.class, id);
    }

    public PersonaNatural findByDni(String dni) {
        return (PersonaNatural) em.createQuery("Select object(o) from PersonaNatural o Where o.dniPersona = ?1").setParameter(1, dni).getSingleResult();
    }

    public List<PersonaNatural> findAll() {
        return em.createQuery("select object(o) from PersonaNatural as o").getResultList();
    }
}
